package io.gitee.xyuesheng.day08;

import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

public class TestThrow {
    //throws里面，多个异常用逗号分割，如果有父子关系，只要声明一个父异常
    public static void main(String[] args) throws IOException {
        openFile();
    }

    public static void openFile() throws IOException {
        //在当前方法里面，不想处理异常，可以在方法声明里，往上层
        InputStreamReader reader = new InputStreamReader(new FileInputStream("D:\\test.txt"));

        reader.read();

    }

    @Test
    public void testFab() {
        fab(-1);
    }

    public static int fab(int n) {
        if (n <= 0) {
            throw new RuntimeException("参数必须大于等于1");
        }

        if (n == 1 || n == 2) {
            return 1;
        } else {
            return fab(n - 2) + fab(n - 1);
        }


    }

//    public static void main(String[] args)throws IOException {
//
//        InputStreamReader reader=new InputStreamReader(new FileInputStream("D:\\test.txt"));
//
//        reader.read();
//
//    }

    @Test
    public void test1() {
        System.out.println("abc".substring(1));
        System.out.println("abc".substring(4));

        String s = "abc".substring(4);
        try {
            s.length();
        } catch (NullPointerException e) {
            System.out.println(e);
        }


    }


}
